package com.rjwh.dingdong.client.util;

import android.content.Context;
import android.os.Handler;
import android.os.Message;
import android.widget.Toast;

import com.rjwh.dingdong.client.R;


public class MyHandle extends Handler {

    private Context mContext;
    public MyProgressDialog dialog;
    public final static int GETDATA_OK = 0;
    public final static int START = 1;
    public final static int ERROR = 2;
    public final static int UPDATEMSG = 3;
    public HandleListener handleListener;

    // private Map<String, ModulesDTO> oldfilemodulesDTOs;
    // private Map<String, ModulesDTO> modulesDTOs;

    // public MyHandle(Context context) {
    // mContext = context;
    // }

    public MyHandle(Context context) {
        mContext = context;
    }

    // public MyHandle(Context context, String name) {
    // mContext = context;
    // filename = name;
    // }

    public void setff() {
        dialog.setCancelable(false);
    }

    @Override
    public void handleMessage(Message msg) {
        switch (msg.what) {
            case GETDATA_OK:
                if (dialog != null) {
                    dialog.dismiss();
                }
                dialog = null;
                break;
            case START:
                if (dialog == null) {
                    if (msg.obj != null) {
                        dialog = new MyProgressDialog(mContext,
                                R.style.Theme_dialog);
                        dialog.setMessage(msg.obj.toString());
                    } else {
                        dialog = new MyProgressDialog(mContext,
                                R.style.Theme_dialog);
                    }
                    dialog.show();
                } else {
                    if (!dialog.isShowing()) {
                        dialog.show();
                    }
                }
                break;
            case ERROR:
                if (msg.obj != null) {
                    Toast.makeText(mContext, msg.obj.toString(), Toast.LENGTH_SHORT)
                            .show();
                } else {
                }
                if (dialog != null) {
                    dialog.dismiss();
                }
                dialog = null;
                break;
            case UPDATEMSG:
                if (dialog != null) {
                    dialog.setMessage(msg.obj.toString());
                }
                break;

        }
    }

    public void getdataok(int what) {
        Message message = new Message();
        message.what = what;
        this.sendMessage(message);
    }

    public void getdataok(int what, String obj) {
        Message message = new Message();
        message.what = what;
        message.obj = obj;
        this.sendMessage(message);
    }

    public interface HandleListener {
        void getdata_parsexml_ok(Object mlInfoDTOs);

    }

    public void setHandleListener(Object a) {
        handleListener = (HandleListener) a;
    }
}
